<?php
	require("dbfunc.php");
	
	$id = $_GET['id'];
	$user = $_GET['user'];
	$jenis = $_GET['jenis'];
	$jml = $_GET['jml'];
	
	if ($jenis>2){
		//hapus
		if ($jenis==3){
			$jml--;
		}else{
			$jml++;
		}
		$res = mysql_query("DELETE FROM menyukai WHERE idKonten = '$id' AND user = '$user'");
		$res = mysql_query("UPDATE konten SET jmlLike = '$jml' WHERE id = '$id'");
		if($jml==-100){
			$res = mysql_query("SELECT * FROM konten WHERE id = '$id'");
			$row = mysql_fetch_array($qres);
			$usern = $row['userpost'];
			$qres="INSERT INTO achievement (user,jenis) VALUES ('$usern','6')";
			if (!mysql_query($qres,$con))
			{
				die('Error: ' . mysql_error());
			}
		}
	}else{
		//tambah
		if ($jenis==2){
			$jml--;
		}else{
			$jml++;
		}
		$res = mysql_query("INSERT INTO menyukai (idKonten, user, jenis) VALUES ('$id', '$user', '$jenis')");
		$res = mysql_query("UPDATE konten SET jmlLike = '$jml' WHERE id = '$id'");
		if($jml==100){
			$res = mysql_query("SELECT * FROM konten WHERE id = '$id'");
			$row = mysql_fetch_array($qres);
			$usern = $row['userpost'];
			$qres="INSERT INTO achievement (user,jenis) VALUES ('$usern','5')";
			if (!mysql_query($qres,$con))
			{
				die('Error: ' . mysql_error());
			}
		}
	}
	
	echo "$jml";
?>